package bookstore.model;

import javax.persistence.Entity;
import java.util.Objects;

@Entity
public class OrderItem {
    private OrderItemPK orderItemPK;
    private int price;
    private int count;

    public OrderItemPK getOrderItemPK() {
        return orderItemPK;
    }

    protected void setOrderItemPK(OrderItemPK orderItemPK) {
        this.orderItemPK = orderItemPK;
    }

    public Long getOrderid() {
        return orderItemPK.getOrderid();
    }

    public void setOrderid(Long id) {
        if (orderItemPK == null) {
            orderItemPK = new OrderItemPK();
        }
        orderItemPK.setOrderid(id);
    }

    public Book getBook() {
        return orderItemPK.getBook();
    }

    public void setBook(Book book) {
        if (orderItemPK == null) {
            orderItemPK = new OrderItemPK();
        }
        orderItemPK.setBook(book);
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OrderItem orderItem = (OrderItem) o;
        return price == orderItem.price &&
                count == orderItem.count &&
                Objects.equals(orderItemPK, orderItem.orderItemPK);
    }

    @Override
    public int hashCode() {

        return Objects.hash(orderItemPK, price, count);
    }


}
